<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<%
	String path = request.getContextPath();
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>活动线索</title>
<link rel="stylesheet" type="text/css" href="<%=path%>/hplus/css/bootstrap.min.css"/>
<link rel="stylesheet" type="text/css" href="<%=path%>/hplus/css/style.min.css"/>
<link rel="stylesheet" type="text/css" href="<%=path%>/hplus/css/font-awesome.min93e3.css"/>
<link rel="stylesheet" type="text/css" href="<%=path%>/bc/css/clue.css"/>
</head>
<body class="gray-bg">
<div class="container-fluid">
	<div class="row activity1">
	    <div class="col-sm-12">
	        <div class="ibox float-e-margins">
	            <div class="ibox-title">
	                <h5><span id="activityCount">0</span> 条线索源于活动</h5>
	            </div>
	            <div class="ibox-content">
	            	<div class="row">
	            		<div class="col-sm-5">
	            			<ul class="progressbarUl2"></ul>
	            		</div>
	            	</div>
	            	<div id="nothing" style="text-align: center;display: none;">
           				<img src="<%=path%>/images/icon_hd.png">
           				<p>您还没有活动 <a href="<%=path%>/api/bm/ui/createActivity1">去创建活动&gt;</a></p>
           			</div>
	            </div>
	        </div>
	    </div>
	</div>
	
	<div class="row activity2">
	    <div class="col-sm-12">
	        <div class="ibox float-e-margins">
	            <div class="ibox-title">
	               <ul class="ulH">
						<li>暂无活动</li>
					</ul>
	            </div>
	            <div class="ibox-content">
	                <table class="table table-hover">
	                	<thead>
	                        <tr>
	                            <th>姓名</th>
	                            <th>行为</th>
	                            <th>来源</th>
	                            <th>时间</th>
	                            <th>操作</th>
	                        </tr>
	                    </thead>
	                    <tbody>
	                    </tbody>
	                </table>
	            </div>
	        </div>
	    </div>
	</div>
</div>
</body>
<script type="text/javascript" src="<%=path%>/hplus/js/jquery.min.js"></script>
<script type="text/javascript" src="<%=path%>/hplus/js/bootstrap.min.js"></script>

<script type="text/javascript" src="<%=path%>/bc/js/clue_title.js"></script>
<script type="text/javascript" src="<%=path%>/js/page.js"></script>
<script type="text/javascript">
var startIndex = 0;
var pageSize = 10;
var keyWord = "";
var currentPage = 1;
var pageCount = 0;

var customerId = 0;	//客户id
var actionId = 0;	//客户行为id

$(function(){
	init();
	
	$(document).on('click','.activity2 .ulH>li',function(){
        keyWord = $(this).attr("keyWord");
        init();
    });
	
	/*聊天点击开始*/
	$(document).on("click",".s_icon_dialogue",function(){
		//初始化数据，全部设置0
		top.customerId = 0;
		top.actionId = 0;
		top.clueWeiboId = 0;
		top.writeOffId = 0;
		
		customerId = $(this).attr("customerId");
		actionId = $(this).attr("actionId");
		
		top.customerId = customerId;
		top.actionId = actionId;
		top.clueWeiboId = 0;
		
		var d = top.dialog({
			fixed: true,
			zIndex: 10000,
			padding:0,
			width:1172,
			height:568,
			title:'沟通记录',
			url:"<%=path%>/api/customer_action/customerChatView",
			cancelDisplay: false,
			cancel: function () {
				if(top.customerChatChange == 1){
					top.customerChatChange = 0;
				}
				top.customerId = 0;
				top.actionId = 0;
				top.clueWeiboId = 0;
				return true;
			}
		});
		d.showModal();
	});
	/*聊天点击结束*/
});

function init(){
	$.post("${pageContext.request.contextPath}/api/weibo/showfirstpage",function(data){
		data = eval(data);
		if(data.showstatus == 1){
			;
		}else if(data.showstatus == 0){
			$(".m_xmanage>a:eq(1)").css("display","none");
		}
	});
	
	$.post('<%=path%>/api/clue_customer/clue_activity',{"startIndex":startIndex,"pageSize":pageSize,"keyWord":keyWord},function(data){
		data = JSON.parse(data);
		
		setFirst(data.activity_name_list,data.weibo_activity_count);
		
		setSecond(data.activity_clue_list);
		
		page(data.totalCount);
	});
}

function setFirst(key_word_list,keyword_count){
	var total = 0;
	
	var startStr = "";
	var endStr = "";
	
	$(".activity2 ul.ulH").html('<li keyWord=""><span>全部</span></li>');
	
	//这个循环计算总数
	for ( var i = 0; i < keyword_count.length; i++) {
		if(i >= 5){
			break;
		}
		var a = keyword_count[i];
		total += a.count;
	}
	
	for ( var i = 0; i < keyword_count.length; i++) {
		if(i >= 5){
			break;
		}
		var a = keyword_count[i];
		
		$(".activity2 ul.ulH").append('<li keyWord="'+a.activityName+'"><span>'+a.activityName+'</span></li>');
        var length_baifenbi = a.count/total*100;
        if(length_baifenbi == 0)
        	length_baifenbi = 2;
        if(total == 0)
        	length_baifenbi = 2;
        startStr += '<li keyWord="'+a.activityName+'"><span>'+a.activityName+'</span><div><div style="width:'+length_baifenbi+'%;"></div></div><span>'+a.count+'条</span></li>';
	}

	$("#activityCount").text(total);
	
	if(startStr+endStr != ""){
		$(".activity1 .progressbarUl2").html(startStr+endStr);
	}else{
		$(".activity1 #nothing").show();
		$(".activity2").css("display","none");
	}
	
	$(".activity2 ul.ulH>li[keyWord='"+keyWord+"']").addClass("focus");
}

function setSecond(weibo_clue_list){
	var tr = "";
	for(var i = 0; i < weibo_clue_list.length; i++){
		var a = weibo_clue_list[i];
		
		var now = new Date();
		var old = new Date(a.createTimeStr);
		var m_date = parseInt((now.getTime() - old.getTime())/1000/60);
		if(m_date >= 100){
			m_date = a.createTimeStr;
		}else{
			m_date += "分钟前";
		}
		
		tr += '<tr><td><img style="height:40px;width:40px;" src="'+((a.avatar == null || a.avatar == undefined || a.avatar == "") ? path+"/images/000head_pic.png" : a.avatar)+'"><a href="'+path+'/api/custome/customerInfo?customerID='+a.id+'">'+a.name+'</a></td><td>'+a.content+'</td><td>'+getSourceTitle(a.source)+'</td><td>'+m_date+'</td><td width="80px">';
		tr += '<shiro:hasPermission name="customer_clue_delete_button"><a class="xiaoTuBiao xtb_dialog"></a></shiro:hasPermission>';
		tr += '<shiro:hasPermission name="customer_clue_chat_button"><a class="xiaoTuBiao xtb_del"></a></shiro:hasPermission></td></tr>';
	}
	$(".activity2 tbody").html(tr);
}

function delClueActivity(id){
	$(".j_popup_box").show();
	$(".j_popup_box .j_popup_box_confirm").unbind("click");
	$(".j_popup_box .j_popup_box_confirm").one("click",function(){
		$.post("<%=path%>/api/clue_customer/delClueActivity",{clueActivityId:id},function(data){
			init();
			$(".j_popup_box").hide();
		});
	});
}

function getSourceTitle(source){
	var title;
	switch (source) {
	case "1":
		title="微博";
		break;
	case "2":
		title="微信";
		break;
	case "3":
		title="QQ";
		break;
	case "4":
		title="活动";
		break;
	case "5":
		title="pc网页";
		break;
	default:
		title="未知";
		break;
	}
	return title;
	
}
</script>
</html>